<?php
/**
 * @author zhaofei
 * @package demo global config 
 * @createtime 2014-11-25
 * @updatetime 2014-11-25
 * @ps:系统全局配置
 */
namespace System\Model;
use Think\Model;
class EmployeeModel extends Model{

	protected $_validate =array(
		array('true_name','require','用户名不能为空',self::MODEL_BOTH),
		array('true_name','','帐号名称已经存在！',0,'unique',self::MODEL_INSERT), // 在新增的时候验证name字段是否唯一
		array('tel','number','电话号码格式不正确',self::MODEL_BOTH),
		array('qq','number','qq格式不正确',self::MODEL_BOTH),
		array('email','email','邮箱格式错误',self::MODEL_BOTH),
		array('ranks',array(1,2,3,4),'级别值的范围不正确！',2,'in'),

	);
	
	protected $_auto = array (
		array('status',1,self::MODEL_INSERT),
		array('create_time','time',self::MODEL_INSERT,'function'),
		array('ct_by_id','getId',self::MODEL_INSERT,'callback'),
		array('update_time','time',self::MODEL_BOTH,'function'),
		array('up_by_id','getId',self::MODEL_BOTH,'callback'),
	);

	public function getId(){
		return session('id');
	}
	//$parms is array
	public function findByAttr($parms){
		$res = D('Employee')->where($parms)->find();
		if(!$res){
			return false;
		}else{
			return $res;
		}
	}

	public function getNameById($userId){
		$parms = array('id'=>$userId);
		$res = D('Employee')->field('true_name')->where($parms)->find();
		if(!$res['true_name']){
			return '未获得';
		}else{
			return $res['true_name'];
		}
	}

	public function saveLoginInfo($rs){
		foreach ($rs as $key => $value) {
			session($key,$value);
		}
		switch (session('ranks')) {
			case 1:$url = U('Super/index');
				break;
			case 2:$url = U('Examine/index');
				break;
			case 3:$url = U('Amaldar/index');
			break;
			case 4:$url = U('staff/index');
			break;
			default: $url = '';
				# code...
				break;
		}
		return $url;
	}
}
?>